public class ArrayQueue<E> implements Queue {


    ArrayMy<E> arrayMy;

    public ArrayQueue() {
        arrayMy = new ArrayMy<>();
    }

    public ArrayQueue(int capacity) {
        arrayMy = new ArrayMy<>(capacity);
    }

    @Override
    public int getSize() {
        return arrayMy.getSize();
    }

    @Override
    public boolean isEmpty() {
        return arrayMy.isEmpty();
    }

    @Override
    public void enQueue(Object o) {

        arrayMy.addLast((E) o);
    }

    @Override
    public Object deQueue(Object o) {
        return arrayMy.removeFirst();
    }


    @Override
    public Object pop() {
        return arrayMy.removeLast();
    }

    @Override
    public Object peek() {
        return arrayMy.getLast();
    }

    @Override
    public String toString() {

        StringBuilder res = new StringBuilder();

        res.append("QUEUE：");
        res.append("[FRONT ");

        for (int i = 0; i < arrayMy.getSize(); i++) {
            res.append(arrayMy.get(i));

            if (i != arrayMy.getSize() - 1) {
                res.append(",");
            }
        }
        res.append("] TAIL");
        return res.toString();
    }

    public static void main(String[] args) {

        ArrayQueue<Integer> queue = new ArrayQueue<>();
        for (int i = 0; i < 10; i++) {
            queue.enQueue(i);
            System.out.println(queue);
            if (i % 3 == 0) {
                System.out.println("=========\n");
                /**
                 * 注意这里删除的操作复杂度是O(n)*/
                queue.deQueue(queue);
                System.out.println(queue);
            }
        }
    }
}
